#include <stdio.h>
#include <sys/types.h>          /* See NOTES */
#include <sys/socket.h>
#include <netinet/in.h>
#include <pthread.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <string.h>
#include "serverfunc.h"


int main(int argc, const char *argv[])
{
	int sockfd=socket(AF_INET,SOCK_STREAM,0);
	struct sockaddr_in serveraddr,clientaddr;
	pthread_t mythread;
	serveraddr.sin_addr.s_addr=inet_addr(argv[1]);
	serveraddr.sin_port=htons(atoi(argv[2]));
	serveraddr.sin_family=AF_INET;

	socklen_t len=sizeof(serveraddr);
	bind(sockfd,(struct sockaddr *)&serveraddr,len);
	listen(sockfd,10);

	H=creat();
	h=creatuserlink();
	while(1)
	{
		int acceptfd=accept(sockfd,(struct sockaddr *)&clientaddr,&len);
		printf("client [%s] has connect\n",inet_ntoa(clientaddr.sin_addr));
		pthread_create(&mythread,NULL,&acceptpthread,&acceptfd);
		pthread_detach(mythread);
	}

	return 0;
}
